package May._02.homework.work3;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        HashMap<String, User> map = new HashMap<>();
        map.put("zs", new User("zs", 18));
        map.put("ls", new User("ls", 19));
        map.put("wu", new User("wu", 20));
        map.put("zl", new User("zl", 21));
        map.put("aa", new User("aa", 18));

        LinkedList<String> keys = new LinkedList<>();
        //本循环结合迭代器使用可以简化代码。无需现在这么麻烦
        for (Map.Entry<String, User> userEntry : map.entrySet()) {
            if(userEntry.getValue().getAge()==18){
                keys.add(userEntry.getKey());
            }
        }
        for (String key : keys) {
            map.remove(key);
        }
        System.out.println("map = " + map);
    }
}
